//
//  NearbyContactCell.m
//  QuanZiChat
//
//  Created by 张洪林 on 15/11/30.
//  Copyright © 2015年 ZhongHongLin. All rights reserved.
//

#import "NearbyContactCell.h"
#import "ZHLWebImage.h"
#import <AVOSCloud.h>
#import <UIImageView+WebCache.h>
#define KEY_HEADIMAGE @"headImage"

@implementation NearbyContactCell


-(void)setPresonInfo:(PresonInfo *)presonInfo{
    if (_presonInfo != presonInfo) {
        _presonInfo = nil;
        _presonInfo = presonInfo;
        [self layoutModel];
    }
}
-(void)layoutModel{
    self.userName.text = self.presonInfo.username;
    self.sex.text = self.presonInfo.sex;
    self.indiv.text = self.presonInfo.indiciduality;
    
    [self layoutImageView];
    [self layoutDistance];
}

-(void)layoutDistance{
    if (self.presonInfo.distance >= 1) {
        self.userLocation.text = [NSString stringWithFormat:@"%.2f Km",self.presonInfo.distance];
    }
    if (self.presonInfo.distance < 1) {
        self.userLocation.text = [NSString stringWithFormat:@"%.2f m",self.presonInfo.distance * 1000];
    }
}
-(void)layoutImageView{
    
    AVQuery *query = [AVQuery queryWithClassName:@"_User"];
    AVUser *user = (AVUser *)[query getObjectWithId:self.presonInfo.userID];
    AVFile* avatar=[user objectForKey:KEY_HEADIMAGE];
    self.userImage.layer.masksToBounds = YES;
    self.userImage.clipsToBounds = YES;
    self.userImage.layer.cornerRadius = 30;
    [self.userImage sd_setImageWithURL:[NSURL URLWithString:avatar.url]];
    
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
